package com.example.demo20250926.config;

import com.example.demo20250926.interceptor.LoginValidationInterceptor;
import org.springframework.context.annotation.Configuration;
import org.springframework.format.datetime.DateFormatter;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

/**
 * @author sky
 * @date 2025年10月31日 10:02
 * @description
 * @since 1.0.0
 */
@Configuration
public class MvcConfig implements WebMvcConfigurer{
    @Override
    public void addFormatters(org.springframework.format.FormatterRegistry registry) {
        registry.addFormatter(new DateFormatter("yyyy-MM-dd HH:mm:ss"));
    }
    /**
     * 配置拦截器
     * @author sky
     * @date 2025/10/31 11:07
     * @param registry
     */
    @Override
    public void addInterceptors(org.springframework.web.servlet.config.annotation.InterceptorRegistry registry) {
        registry.addInterceptor(new LoginValidationInterceptor()).addPathPatterns("/admin/**");
    }
    @Override
    public void addResourceHandlers(org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry registry) {
        registry.addResourceHandler("/static/**").addResourceLocations("classpath:/static/");
    }
    @Override
    public void addCorsMappings(org.springframework.web.servlet.config.annotation.CorsRegistry registry) {
        registry.addMapping("/api/**").allowedOrigins("http://www.sky.cn").allowedMethods("GET", "POST", "PUT", "DELETE", "OPTIONS");
    }
    @Override
    public void addViewControllers(org.springframework.web.servlet.config.annotation.ViewControllerRegistry registry) {}
    @Override
    public void configurePathMatch(org.springframework.web.servlet.config.annotation.PathMatchConfigurer configurer) {}
}
